#ifndef LEARN_VULKAN_GEOMETRY_H
#define LEARN_VULKAN_GEOMETRY_H
#include "Headers.h"

struct vec2{
    float x, y;
};

struct vec3{
    float x, y, z;
};

struct Vertex {
    vec3 pos;
    vec2 texcoord;
    vec3 normal;

    static VkVertexInputBindingDescription getBindingDescription(){
        VkVertexInputBindingDescription bindingDescription = {
                .binding = 0,
                .stride = sizeof(Vertex),
                .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
        };
        return bindingDescription;
    }

    static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions(){
        std::array<VkVertexInputAttributeDescription, 3> attributeDesc{};
        attributeDesc[0] = {
            .location = 0,
            .binding = 0,
            .format = VK_FORMAT_R32G32B32_SFLOAT,
            .offset = offsetof(Vertex, pos)
        };
        attributeDesc[1] = {
                .location = 1,
                .binding = 0,
                .format = VK_FORMAT_R32G32_SFLOAT,
                .offset = offsetof(Vertex, texcoord)
        };
        attributeDesc[2] = {
                .location = 2,
                .binding = 0,
                .format = VK_FORMAT_R32G32B32_SFLOAT,
                .offset = offsetof(Vertex, normal)
        };
        return attributeDesc;
    }

    static std::array<VkDescriptorSetLayoutBinding, 3> getDescSetLayoutBindings(){
        std::array<VkDescriptorSetLayoutBinding, 3> layoutBindings{};
        layoutBindings[0] = {
                .binding = 0,
                .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
                .descriptorCount = 1,
                .stageFlags = VK_SHADER_STAGE_VERTEX_BIT
        };

        layoutBindings[1] = {
                .binding = 1,
                .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
                .descriptorCount = 1,
                .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
        };

        layoutBindings[2] = {
                .binding = 2,
                .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
                .descriptorCount = 1,
                .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
        };
        return layoutBindings;
    }

    static std::array<VkDescriptorPoolSize, 2> getDescPoolSizes(uint32_t maxFrameCount){
        //TODO???
    }
};

class CGeometry {
public:
    bool bUseIndexDraw() const;
    uint32_t getVertexCount() const;
    uint32_t geIndexCount() const;
    void destroy(VkDevice device);
public:
    std::vector<Vertex>  vertices;
    std::vector<uint32_t> indices;

    VkBuffer vertexBuffer;
    VkDeviceMemory vertexMemory;
    VkBuffer indexBuffer;
    VkDeviceMemory indexMemory;
};


#endif //LEARN_VULKAN_GEOMETRY_H
